<?php
/*
Simple:Press Forum
xhtml to bbCode parser
$LastChangedDate: 2009-01-01 03:25:57 +0000 (Thu, 01 Jan 2009) $
$Rev: 1093 $
*/

function sf_Html2BCode($text)
{
	$text = trim($text);
	$text = stripslashes($text);

	$in = array( 	'/\<strong\>(.*?)\<\/strong\>/ms',	
					'/\<em\>(.*?)\<\/em\>/ms',
					'/\<u\>(.*?)\<\/u\>/ms',
					'/\<img\s+.*src="([^"]+)".*\/\>/ms',
					'/\<a\s+.*href="([^"]+)".*\>(.+)\<\/a\s*\>/ms',
					'/\<blockquote\>(.*?)\<\/blockquote\>/ms',
					'/\<ul\>(.*?)\<\/ul\>/ms',
				 	'/\<li\>\s?(.*?)<\/li\>/ms'
	);
	# And replace them by...
	$out = array(	'[b]\1[/b]',
					'[i]\1[/i]',
					'[u]\1[/u]',
					'[img]\1[/img]',
					'[url="\1"]\2[/url]',
					'[quote]\1[/quote]',
					'[list]\1[/list]',
					'[*]\1'
	);
	$text = preg_replace($in, $out, $text);


	$text = str_replace ("<p>", "", $text);
	$text = str_replace ("</p>", "\r\r", $text);
	$text = str_replace("<br />", "\r", $text);

	$text = str_replace ("<div class=\"sfcode\">", "[code]", $text);
	$text = str_replace ("</div>", "[/code]", $text);

	return $text;
}

?>